﻿using Shumei.EFCore.Model;
using Shumei.EFCore.SimpleService;
using source.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace source.Areas.Admin.Controllers
{
    /// <summary>
    /// 管理登录
    /// </summary>
    public class AccountController : Controller
    {
        UserService userService;
        public AccountController() { userService = new UserService(); }
        //
        // GET: /Admin/Account/
        public ActionResult Login()
       {
            return View("Login");
        }
        public static bool isLogin(HttpContextBase httpContext)
        {
            return httpContext.Session["superUser"] != null;
        }
        public static User GetUserInfo(HttpContextBase httpContext)
        {
            return (User)httpContext.Session["superUser"];
        }
        [HttpPost]
        public ActionResult Login(LoginViewModel loginform)
        {
            var user= userService.Find(loginform.Account);
            
            if(user!=null && loginform.Password == user.password && user.Role == 3 )
            {
                Session["superUser"] = user;
                Session.Timeout = 360;
                return RedirectToAction("Index", "BackGround");
            }
            return View("Login");
        }

        [HttpPost]
        public ActionResult Logout()
        {
            Session["superUser"] = null;
            return View("Login");
        }
	}
}